** Data reading and variable selection from raw data
** 1995 Canadian General Social Survey

** 01. Reading data **

cap log close
clear all
set more off
cd /*insert you work directory here*/
use /*read your data here*/  


** 02. Consructing year and country variables **

ge year=1995
lab var year "survey year"

ge country=124
lab var country "ISO country code"
//Canada: 124 (see "ISO Country Codes.pdf) 


** 03. ID variables **

ge pid=recid
lab var pid "person id"


** 04. Basic Demographics (Sex and Age/birth year) **

ge sex=dvsex
lab var sex "sex"
lab def sex 1 "male" 2 "female"
lab val sex sex

ge age=dvagecap
lab var age "age"

ge birthyr = year - age

lab var birthyr "Year of Birth"


** 05. Siblings **

* number of brothers/sisters does not include respondent. Original measure includes respondent, so we subtract one.

ge nsibs= dvb7cap + dvb17cap

* number of brothers and sisters variables. 

ge nbro = dvb7cap
ge nsis = dvb17cap 

lab var nbro "number of brothers"
lab var nsis "number of sisters"
lab var nsibs "number of siblings"


** 06. Own education **

rename dvl30co educ_cat

lab def educL 1 "DOCTORATE/MASTER" 2 "DIPL/CERT. FROM" 3 "DIPL. FROM TRADE" 4 "SOME UNIVERSITY" 5 "SOME COMMUNITY COLLEGE" 6 "SOME TRADE/TECH/" 7 "HIGH SCHOOL DIPL" 8 "LESS THAN HIGH S" 9 "ELEMENTARY SCHOO" 10 "NO SCHOOLING" 11 "OTHER"

lab val educ_cat educL

lab var educ_cat "highest level of education completed"

ge educ_yrs = .
replace educ_yrs = 9.526 if educ_cat == 11
replace educ_yrs = 0 if educ_cat == 10
replace educ_yrs = 6 if educ_cat == 9
replace educ_yrs = 9.083 if educ_cat == 8
replace educ_yrs = 12 if educ_cat == 7
replace educ_yrs = 12 if educ_cat == 6
replace educ_yrs = 13 if educ_cat == 5
replace educ_yrs = 14 if educ_cat == 4
replace educ_yrs = 13 if educ_cat == 3
replace educ_yrs = 16 if educ_cat == 2
replace educ_yrs = 19.573 if educ_cat == 1

lab var educ_yrs "Years of education completed respondent"


** 07. Parents' education: Father and/or Mother **

rename dva60co faeduc_cat

rename dva36co moeduc_cat

lab var faeduc_cat "father's education level"

lab var moeduc_cat "mother's education level"

lab val faeduc_cat educL

lab val moeduc_cat educL

ge faeduc_yrs = .
replace faeduc_yrs = 9.526 if educ_cat == 11
replace faeduc_yrs = 0 if educ_cat == 10
replace faeduc_yrs = 6 if educ_cat == 9
replace faeduc_yrs = 9.083 if educ_cat == 8
replace faeduc_yrs = 12 if educ_cat == 7
replace faeduc_yrs = 12 if educ_cat == 6
replace faeduc_yrs = 13 if educ_cat == 5
replace faeduc_yrs = 14 if educ_cat == 4
replace faeduc_yrs = 13 if educ_cat == 3
replace faeduc_yrs = 16 if educ_cat == 2
replace faeduc_yrs = 19.573 if educ_cat == 1

lab var faeduc_yrs "Years of education completed - Father"


ge moeduc_yrs = .
replace moeduc_yrs = 9.526 if educ_cat == 11
replace moeduc_yrs = 0 if educ_cat == 10
replace moeduc_yrs = 6 if educ_cat == 9
replace moeduc_yrs = 9.083 if educ_cat == 8
replace moeduc_yrs = 12 if educ_cat == 7
replace moeduc_yrs = 12 if educ_cat == 6
replace moeduc_yrs = 13 if educ_cat == 5
replace moeduc_yrs = 14 if educ_cat == 4
replace moeduc_yrs = 13 if educ_cat == 3
replace moeduc_yrs = 16 if educ_cat == 2
replace moeduc_yrs = 19.573 if educ_cat == 1

lab var moeduc_yrs "Years of education completed - Mother"


** 08. Own occupation **

rename dvsic occ_indus

rename dvsoc occ_code

rename dvpineo occ_sec

rename l11 emp_stat

lab var occ_indus "Standard Industrial Class. Codes"

lab var occ_code "Standard Occupation Codes"

lab var occ_sec "PINEO Socio-Economic Class. of Occup"

lab var emp_stat "Employment status - did the respondent work last week"

** label values **

lab def occ_indusL 1 "TRADITIONAL PRIM" 2  "NON-TRADITIONAL" 3  "NAT. RESOURCES I" 4  "LABOUR INTENSIVE" 5  "SCALE-BASED MANU" 6  "PRODUCT DIFFEREN" 7  "SCIENCE-BASED MA" 8  "CONSTRUCTION" 9  "DISTRIBUTIVE SER" 10  "DISTRIBUTIVE SER" 11  "DISTRIBUTIVE SER" 12  "CONSUMER SERVICE" 13  "CONSUMER SER.:PE" 14  "BUSINESS SERVICE" 15  "SER. TO BUSINESS" 16  "COM.SERVICES:EDU" 17  "COMMUNITY SERVIC" 18  "PUBLIC ADMINISTR"
 
lab def occ_codeL  1  "MANAGERS/ADMINIS" 2  "MANAGEMENT/ADMIN" 3  "LIFE SCIENCES/MA" 4  "ARCHITECTS/ENGIN" 5  "SOCIAL SCIENCE/R" 6  "TEACHING RELATED" 7  "MEDICINE AND HEA" 8  "ARTISTIC/LITERAR" 9  "STENOGRAPHIC/TYP" 10  "BOOKKEEPING/ACCO" 11  "EDP OPERATORS/MA" 12  "RECEPTION/INFO./" 13  "LIBRARY/FILE/OTH" 14  "SALES/COMMODITIE" 15  "SALES/SERVICES" 16  "PROTECTIVE SERVI" 17  "FOOD/BEVERAGE/AC" 18  "PERSONAL/APPAREL" 19  "OTHER SERVICE OC" 20  "FARM OCCUPATIONS" 21  "PRIMARY OCCUPATI" 22  "FOOD/BEV./PROCES" 23  "PROCESSING OCCUP" 24  "MACHINE/RELATED" 25  "ELECTRICAL/ELECT" 26  "TEXTILES/FUR/LEA" 27  "WOOD PRODUCTS/RU" 28  "REPAIRMEN (EXCEP" 29  "EXCAVATING/PAVIN" 30  "OTHER CONSTRUCTI" 31  "TRANSPORT OPERAT" 32  "MATERIAL HANDLIN" 33  "OTHER CRAFTS AND"
      
lab def occ_secL 1  "SELF EMPLOYED PR" 2  "EMPLOYED PROFESS" 3  "HIGH-LEVEL MANAG" 4  "SEMI-PROFESSIONA" 5  "TECHNICIANS" 6  "MIDDLE MANAGEMEN" 7  "SUPERVISORS" 8  "FOREMEN AND FORE" 9  "SKILLED CLERICAL" 10  "SKILLED CRAFTS A" 11  "FARMERS" 12  "SEMI-SKILLED CLE" 13  "SEMI-SKILLED MAN" 14  "UNSKILLED CLERIC" 15  "UNSKILLED MANUAL" 16  "FARM LABOURERS"

lab def emp_statL 1 "YES" 2 "NO"

lab val occ_indus occ_indusL

lab val occ_code occ_codeL

lab val occ_sec occ_secL

lab val emp_stat emp_statL


** 09. Parents' occupation **

//not available


** 10. Tabulate the Identified Variables **

log using /*read your data here*/, replace text

** Data reading and variable selection from raw data
** 1995 Canadian General Social Survey

** Sex **
tab sex

** Age, Birth Year **
sum age birthyr, d

** Siblings **
sum nsibs nsis nbro, d

** R's Own Education **
tab1 educ_cat educ_yrs

** Parental Education **
tab1 faeduc_cat moeduc_cat faeduc_yrs moeduc_yrs

** R's Own Occupation **
tab1 occ_code occ_indus occ_sec emp_stat

log close

** 11. Keep the identified variables only

keep year country pid sex age birthyr ///
	 nsibs nsis nbro ///
	 educ_cat educ_yrs faeduc_cat moeduc_cat faeduc_yrs moeduc_yrs ///
	 occ_code occ_indus occ_sec emp_stat

	 
**Create ISCED Education Variable**

ge educ_ISCED = .
replace educ_ISCED = 300 if educ_cat == 11
replace educ_ISCED = 000 if educ_cat == 10
replace educ_ISCED = 100 if educ_cat == 9
replace educ_ISCED = 200 if educ_cat == 8
replace educ_ISCED = 300 if educ_cat == 7
replace educ_ISCED = 400 if educ_cat == 6
replace educ_ISCED = 400 if educ_cat == 5
replace educ_ISCED = 500 if educ_cat == 4
replace educ_ISCED = 500 if educ_cat == 3
replace educ_ISCED = 600 if educ_cat == 2
replace educ_ISCED = 750 if educ_cat == 1

ge moeduc_ISCED = .
replace moeduc_ISCED = 300 if moeduc_cat == 11
replace moeduc_ISCED = 000 if moeduc_cat == 10
replace moeduc_ISCED = 100 if moeduc_cat == 9
replace moeduc_ISCED = 200 if moeduc_cat == 8
replace moeduc_ISCED = 300 if moeduc_cat == 7
replace moeduc_ISCED = 400 if moeduc_cat == 6
replace moeduc_ISCED = 400 if moeduc_cat == 5
replace moeduc_ISCED = 500 if moeduc_cat == 4
replace moeduc_ISCED = 500 if moeduc_cat == 3
replace moeduc_ISCED = 600 if moeduc_cat == 2
replace moeduc_ISCED = 750 if moeduc_cat == 1

ge faeduc_ISCED = .
replace faeduc_ISCED = 300 if faeduc_cat == 11
replace faeduc_ISCED = 000 if faeduc_cat == 10
replace faeduc_ISCED = 100 if faeduc_cat == 9
replace faeduc_ISCED = 200 if faeduc_cat == 8
replace faeduc_ISCED = 300 if faeduc_cat == 7
replace faeduc_ISCED = 400 if faeduc_cat == 6
replace faeduc_ISCED = 400 if faeduc_cat == 5
replace faeduc_ISCED = 500 if faeduc_cat == 4
replace faeduc_ISCED = 500 if faeduc_cat == 3
replace faeduc_ISCED = 600 if faeduc_cat == 2
replace faeduc_ISCED = 750 if faeduc_cat == 1


** 12. Save the Data File **

saveold /*read your data here*/, replace

